package com.illumination.monitor.common.utils;

import com.illumination.monitor.common.enums.ResultEnum;
import com.illumination.monitor.common.vo.ResultVO;

public class ResultVOUtil {
	
	/** 请求成功 */
	public static <T> ResultVO<T> success(T object) {
		ResultVO<T> resultVO = new ResultVO<>();
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMessage("成功");
		resultVO.setData(object);
		return resultVO;
	}

	/** 请求成功 */
	public static ResultVO<?> success() {
		return success(null);
	}

	/** 请求失败 */
	public static ResultVO<?> error(Integer code, String message) {
		ResultVO<?> resultVO = new ResultVO<>();
		resultVO.setCode(code);
		resultVO.setMessage(message);
		resultVO.setData(null);
		return resultVO;
	}
	
	/** 请求失败 */
	public static ResultVO<?> error(ResultEnum e) {
		ResultVO<?> resultVO = new ResultVO<>();
		resultVO.setCode(e.getCode());
		resultVO.setMessage(e.getMessage());
		resultVO.setData(null);
		return resultVO;
	}
	
	/** 请求错误 */
	public static ResultVO<?> error(String message) {
		ResultVO<?> resultVO = new ResultVO<>();
		resultVO.setCode(ResultEnum.FAIL.getCode());
		resultVO.setMessage(message);
		resultVO.setData(null);
		return resultVO;
	}
	
	/** 请求错误 */
	public static ResultVO<?> paramError(String message) {
		ResultVO<Object> resultVO = new ResultVO<>();
		resultVO.setCode(ResultEnum.FAIL.getCode());
		resultVO.setMessage("JSON参数格式有误");
		resultVO.setData(message);
		return resultVO;
	}

	/** 请求错误 */
	public static ResultVO<?> fail(String message) {
		ResultVO<?> resultVO = new ResultVO<>();
		resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
		resultVO.setMessage(message);
		resultVO.setData(null);
		return resultVO;
	}
	
	/** 请求错误 */
	public static ResultVO<?> error(Object object) {
		ResultVO<Object> resultVO = new ResultVO<>();
		resultVO.setCode(ResultEnum.FAIL.getCode());
		resultVO.setMessage(ResultEnum.FAIL.getMessage());
		resultVO.setData(object);
		return resultVO;
	}
	
	
	/** 请求错误 */
	public static ResultVO<?> error(ResultEnum en,Object object) {
		ResultVO<Object> resultVO = new ResultVO<>();
		resultVO.setCode(en.getCode());
		resultVO.setMessage(en.getMessage());
		resultVO.setData(object);
		return resultVO;
	}

}
